/*
 *@author lwh created
 *
 *
 *
 */
#include "thread_pool.h"

void mkdirCommand(task_t * task)
{
    char file_name[128] = {0};
    strcpy(file_name, task->data);
    

    //获得当前目录的id, 作为创建目录的parent_id; 
    int uid;
    int path_id;
    mkdir_get_dir_id(task->sp, task->name, &uid, &path_id);

    //判断当前目录中是否存在相同目录
    int exist_flag = isExist_virtual_file(task->sp, file_name, path_id, uid, 'd');
    if(exist_flag == 0){

        //获取当前目录路径
        char path[512] = {0};
        get_pwd(task->sp, path_id, uid, path);

        insert_virtual_file(task->sp, path_id, file_name, uid, "0", 0, 'd', path); 
    }else{
        char sendline[128] = {0};
        sprintf(sendline, "mkdir: 无法创建目录 \"%s\": 文件已存在", file_name);
        send(task->peerfd, sendline, strlen(sendline), 0);
    }
   // int ret = mkdir(file_name, 0777);
   // if(ret == -1){
   //     printf("mkdir_err");
   //     exit(-1);
   // }

}

